package org.tech4j.edi.persistence.jdbc.util;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

import java.util.List;
import java.util.Map;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/8 10:42
 **/
public class DefaultJdbcListFactory implements JdbcListFactory {
    private final NamedParameterJdbcTemplate jdbcTemplate;

    public DefaultJdbcListFactory(NamedParameterJdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public <T> List<T> getList(String sql, Map<String, Object> parameters, RowMapper<T> rowMapper) {
        return jdbcTemplate.query(sql, parameters, rowMapper);
    }

    @Override
    public Long count(String sql, Map<String, Object> parameters) {
        return jdbcTemplate.queryForObject(sql, parameters, Long.class);
    }
}
